package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.ContactAddRequest;
import com.frogs.ucenter.v1.request.FollowedUserAttentionInfoRequest;
import com.frogs.ucenter.v1.request.FollowedUserAttentionVerifyRequest;
import com.frogs.ucenter.v1.request.UserAttentionAddRequest;
import com.frogs.ucenter.v1.request.UserAttentionDeleteRequest;
import com.frogs.ucenter.v1.request.UserAttentionInfoRequest;
import com.frogs.ucenter.v1.request.UserAttentionListRequest;
import com.frogs.ucenter.v1.request.UserAttentionUpdateRequest;
import com.frogs.ucenter.v1.request.UserAttentionWeightUpdateRequest;
import com.frogs.ucenter.v1.service.UserAttentionService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Controller(ApiConstants.VERSION + "userAttentionController")
@RequestMapping("/" + ApiConstants.VERSION )
public class UserAttentionController extends BaseController3 {
	
	private static final Logger log = LoggerFactory.getLogger(UserAttentionController.class);

	private static final String ROOT = "/user";
	
	private static final String USER_ATTENTION_LIST = ROOT + "/attention/list";
	private static final String USER_ATTENTION_ADD = ROOT + "/attention/add";
	private static final String USER_ATTENTION_DELETE = ROOT + "/attention/delete";
	private static final String USER_ATTENTION_DETAIL = ROOT + "/attention/detail";
	private static final String USER_ATTENTION_VERIFY = ROOT + "/attention/verify";
	private static final String FOLLOWED_ATTENTION_DETAIL = "/followed/attention/detail";
	private static final String USER_ATTENTION_UPDATE = ROOT + "/attention/update";
	private static final String USER_ATTENTION_WEIGHT_UPDATE = ROOT + "/attention/weight/update";
	private static final String USER_ATTENTION_COUNT = ROOT + "/attention/count";
	
	private static final String USER_CONTACT_ADD = ROOT + "/contact/add";
	
	@Resource(name=ApiConstants.VERSION+"userAttentionService")
	private UserAttentionService userAttentionService;
	
	@RequestMapping(USER_ATTENTION_LIST)
	public Response attentionList(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionListRequest req = new UserAttentionListRequest();
			req.parse(request);
			response = userAttentionService.getList(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_COUNT)
	public Response attentionCount(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionListRequest req = new UserAttentionListRequest();
			req.parse(request);
			response = userAttentionService.getCount(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_ADD)
	public Response attentionAdd(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionAddRequest req = new UserAttentionAddRequest();
			req.parse(request);
			response = userAttentionService.insert(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_DELETE)
	public Response attentionDelete(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionDeleteRequest req = new UserAttentionDeleteRequest();
			req.parse(request);
			response = userAttentionService.delete(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_DETAIL)
	public Response attentionInfo(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionInfoRequest req = new UserAttentionInfoRequest();
			req.parse(request);
			response = userAttentionService.getAttentionInfo(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(FOLLOWED_ATTENTION_DETAIL)
	public Response followedAttentionInfo(HttpServletRequest request) {
		Response response = null ; 
		try{
			FollowedUserAttentionInfoRequest req = new FollowedUserAttentionInfoRequest();
			req.parse(request);
			response = userAttentionService.getFollowAttentionInfo(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_VERIFY)
	public Response verifyFollowedAttentionInfo(HttpServletRequest request) {
		Response response = null ; 
		try{
			FollowedUserAttentionVerifyRequest req = new FollowedUserAttentionVerifyRequest();
			req.parse(request);
			response = userAttentionService.verifyAttention(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_WEIGHT_UPDATE)
	public Response attentionWeightUpdate(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionWeightUpdateRequest req = new UserAttentionWeightUpdateRequest();
			req.parse(request);
			response = userAttentionService.updateWeight(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_UPDATE)
	public Response attentionUpdate(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserAttentionUpdateRequest req = new UserAttentionUpdateRequest();
			req.parse(request);
			response = userAttentionService.update(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 添加联系人接口
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(USER_CONTACT_ADD)
	public Response userContactAdd(HttpServletRequest request) {
		Response response = null ; 
		try{
			ContactAddRequest req = new ContactAddRequest();
			req.parse(request);
			response = userAttentionService.addContact(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
}
